 <?php
class noticeModel extends Model
{
    
    /**
     * 取到我有权限查看的公告
     * 的查询条件 
     */ 
    public function noticeWhere($regionIds=null){
		$admin = getUserSession();
		
		if(isset($admin['cityId']) && $admin['cityId']){
			$string = '';
			foreach ($admin['cityId'] as $cityId){
				$string .= " FIND_IN_SET('{$cityId}',`regionId`) OR";
			}
			$map['_string'] = rtrim($string,'OR');
		}
        $map['status'] = 1;
        return $map;
    }
    
    public function myNotice($order='',$regionIds=null){
        $map = $this->noticeWhere($regionIds);
        if(empty($order)){
            $order = 'publishTime desc';
        }        
        $list = $this->field('id,title,att,publishTime,channel')->where($map)->order($order)->select();      
        return $list;        
    }

  
    /**
	 * 修理存储在数据表中 att 字段的附件信息
	 */
	public function getAttachment($att){
		$data = array();
		$att = json_decode($att, true);
		if($att){
			$filename = C('pin_attach_path').'notice/'.$att['savename'];
			$data['save_name'] = $filename;
			$data['name'] = $att['name'];

		}
		return $data;
	}
}